package com.ljf.auto;

import com.ljf.interceptor.TokenWebConfig;
import com.ljf.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration(after = TokenAutoConfigure.class)
@EnableConfigurationProperties(TokenInterceptorProperties.class)
@ConditionalOnClass(value = {HandlerInterceptor.class, WebMvcConfigurer.class})
@ConditionalOnProperty(prefix = "token.interceptor", name = "enabled", matchIfMissing = true)
public class TokenInteceptorAutoConfigure {
    /**
     * 向容器注入 webmvc配置类
     *
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer(TokenInterceptorProperties properties, TokenTemplate tokenTemplate) {
        TokenWebConfig webConfig = new TokenWebConfig(properties, tokenTemplate);
        return webConfig;
    }
}
